//
//  AddImageBtn.m
//  YaoHeAPP
//
//  Created by mac on 15/12/1.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "AddImageBtn.h"

@implementation AddImageBtn
@synthesize center;
- (id)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        imageViewb=[[UIImageView alloc]init];
        [self addSubview:imageViewb];

    }
    return self;
}

-(void)setImageState:(ImageState)imageState
{
    
    _imageState=imageState;
//    UIImageView*imageView=[[UIImageView alloc]init];
//    [self addSubview:imageView];
//    [self bringSubviewToFront:imageView];
    switch (imageState) {
        case AddImage:
        {
            //[imageView removeFromSuperview];
            imageViewb.image=[UIImage imageNamed:@"addimage"];
           imageViewb.frame=CGRectMake(self.frame.size.width/2-15, self.frame.size.width/2-15, 30, 30);
            self.layer.borderColor=[UIColor grayColor].CGColor;
            
        }
            break;
        
        case DeleteImage:
        {
            imageViewb.frame=CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
            imageViewb.image=self.backImage;

//            UIImageView*imageView=[[UIImageView alloc]init];
//            [self addSubview:imageView];
            self.layer.borderColor=[UIColor redColor].CGColor;
            //[self setBackgroundImage:self.backImage forState:UIControlStateNormal];
            deleteBtn=[UIButton buttonWithType:UIButtonTypeCustom];
           // deleteBtn.tag=btnTag+10;
            deleteBtn.frame=CGRectMake(self.frame.size.width-8, -8, 20, 20);
            [deleteBtn setBackgroundImage:[UIImage imageNamed:@"cancelimage"] forState:UIControlStateNormal];
            [deleteBtn addTarget:self action:@selector(deleteImage) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:deleteBtn];
            [self bringSubviewToFront:deleteBtn];
            
        }
            break;
        
        case Select:
        {
             [self setTitleColor:[UIColor colorWithRed:40.f/255.f green:193.f/255.f blue:226.f/255.f alpha:1] forState:UIControlStateNormal];
        }
            break;
       
        case Unselect:
        {
            //[self removeFromSuperview];
            [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        }

            break;
        default:
            break;
    }
}

- (void)deleteImage {
    [deleteBtn removeFromSuperview];
    self.imageState=AddImage;
}

@end
